Elisabeth Dahlqwist & Nissa Ferm
R-Ladies Stockholm on October 23, 2019
As of this year

FastrCAT…

Basics
Package design decision examples:

Wikipedia defines human readable as,
“A human-readable medium or human-readable format is a representation of data or information that can be naturally read by humans.”
As humans we are great at telling stories, your code is a narrative
arctic_fish_data_clean.csv
finalFINAL_final I really mean it pleaseBE done.csv
friend_group <- c("Dominique", "Hollis", "Sam", "Robyn", "Ridley")
acorn_count <- c(1, 3, 5, 7, 2, 0)
who_called <- function(friend_group){"Who called me?"}
feed_the_squirrel <- function(acorn_count){"Do I have enough acorns to feed each squirrel?"}
We all love to write documentation 😐

# Determines if file has header information -----------------------------------
if(length(grep("@ ", full_table,ignore.case = TRUE)) == 0){
no_head_files[[i]] <- paste("This file", temp[i],
"has no header info needs to be reprocessed.",
sep = " ")
warning(paste("This file", temp[i],
"has no header info, needs to be reprocessed.", sep = " "))
next()
}else{
No_head_files <-if(is.null(no_head_files) == TRUE){
"All header information entered into MasterCOD. High Five!"
} else {
data.frame(unlist(no_head_files))
}
Dependencies are the other packages your package needs to run. You should try and ask yourself these questions
Mapping function dependencies
# bring in the shape files to make the basemap --------------------------------
MAP <- sf::st_read(dsn = system.file("extdata", package = "FastrCAT"),
layer = "Alaska_dcw_polygon_Project", quiet = TRUE)
system.file("extdata", package = "FastrCAT")

“Good design is actually a lot harder to notice than poor design, in part because good designs fit our needs so well that the design is invisible, serving us without drawing attention to itself. Bad design, on the other hand, screams out its inadequacies, making itself very noticeable.”
Donald A. Norman, The Design of Everyday Things
Summary of glm object
> summary(fit)
Call:
glm(formula = Y ~ X + Z + X * Z, family = binomial, data = data)
Deviance Residuals:
Min 1Q Median 3Q Max
-2.4742 -0.8863 0.4277 0.8371 2.3265
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -0.1806 0.1079 -1.674 0.0941 .
X 1.0075 0.1544 6.525 6.8e-11 ***
Summary of AFglm object
> summary(AFglm_est)
Call:
AFglm(object = fit, data = data, exposure = "X")
Estimated attributable fraction (AF) and untransformed 95% Wald CI:
AF Std.Error z value Pr(>|z|) Lower limit Upper limit
0.1664325 0.03027685 5.497019 3.862643e-08 0.1070909 0.225774

Today we learned
We can have different experiences/reasons to build packages
Meet your users where they are at and support them
You should Document, Document, Document…nDocument
When you are ready to build a package there is a whole community to support you.
Writing an R package from scratch, Hilary Parker of Not So Standard Deviations
https://hilaryparker.com/2014/04/29/writing-an-r-package-from-scratch/
R Packages by Hadley Wickam
http://r-pkgs.had.co.nz/
R Packages: The Whole Game by Jenny Bryan
https://r-pkgs.org/whole-game.html
also see https://stat545.com/
R package primer by Karl Broman
https://kbroman.org/pkg_primer/

Find all the slides and code here https://github.com/R-Ladies-Stockholm/Package-Basics-Presentation
Follow us on Twitter @RLadiesSthlm or Facebook @RLadiesStockholm
In the near future 5 minute favorite package talks and Package building workshop!
And now for a quick package building demo.